<template>
  <div class="relationVideo">
    <section-title sectionName="相关视频" :showMore="false" />
    <div
      class="relationVideoItem w"
      v-for="(item, index) in filterRelationVideo"
      :key="item.vid"
      :class="{ active: index === currentPlayIndex - 1 }"
      @click="relationVideoClick(index)"
    >
      <div class="leftBanner">
        <img :src="item.coverUrl" alt="" />
        <div class="videoInfo">
          <div class="playCount">
            <i class="iconfont icon-shipin"></i>
            <span>{{ item.playTime | playCountFormat }}</span>
          </div>
          <div class="duration">{{ item.durationms | durationFormat }}</div>
        </div>
      </div>
      <div class="rightText">
        <h3 class="title">{{ item.title }}</h3>
        <span class="category">{{ item.creator[0].userName }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import SectionTitle from "@/components/common/SectionTitle.vue";
import { playCountFormat, durationFormat } from "@/utils/index";

export default {
  name: "RelationVideo",
  components: {
    SectionTitle,
  },
  props: {
    relationVideo: {
      type: Array,
      default() {
        return [];
      },
    },
    currentPlayIndex: {
      type: Number,
      default: 0,
    },
  },
  methods: {
    relationVideoClick(index) {
      this.$emit("toggleRelationVideo", index);
    },
  },
  computed: {
    filterRelationVideo() {
      return this.relationVideo.filter((item) => !item.id);
    },
  },
  filters: {
    playCountFormat,
    durationFormat,
  },
};
</script>

<style lang="scss" scoped>
.relationVideoItem.active {
  background-color: #22d59c;
}
.relationVideoItem {
  display: flex;
  margin-bottom: 1rem;
  border-radius: 0.5rem;
  overflow: hidden;
  .leftBanner {
    position: relative;
    width: 40%;
    height: 5rem;
    border-radius: 0.5rem;
    overflow: hidden;
    img {
      width: 100%;
      height: 5rem;
    }
    .videoInfo {
      position: absolute;
      bottom: 0;
      left: 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 1.5rem;
      font-size: 0.8rem;
      color: #fff;
      .playCount {
        padding-left: 0.5rem;
        i.iconfont {
          margin-right: 0.3rem;
          font-size: 1rem;
        }
      }
      .duration {
        padding-right: 0.5rem;
      }
    }
  }
  .rightText {
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    width: 60%;
    padding-left: 0.5rem;
    h3.title {
      font-size: 0.9rem;
      font-weight: 400;
      color: #1a1a1a;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    span.category {
      font-size: 0.8rem;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
    }
  }
}
</style>